package eleven;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.util.Date;

public class UDPObjServer {
    public static void main(String[] args) throws Exception {
        System.out.println("UDPServer 启动中...");
        DatagramSocket server = new DatagramSocket(9999);
        byte[] container = new byte[1024 * 60];
        DatagramPacket packet = new DatagramPacket(container, 0, container.length);
        server.receive(packet);
        byte[] datas = packet.getData();
        int len = packet.getLength();
        ObjectInputStream dis = new ObjectInputStream(new BufferedInputStream(
                new ByteArrayInputStream(datas, 0, len)));
        String msg = dis.readUTF();
        int age = dis.readInt();
        boolean flag = dis.readBoolean();
        char ch = dis.readChar();
        Object str = dis.readObject();
        Object date = dis.readObject();
        Object employee = dis.readObject();
        System.out.println(msg + "--->" + flag);
        System.out.println(age + "--->" + ch);

        if(str instanceof String){
            System.out.println(str);
        }
        if(date instanceof Date){
            System.out.println(date);
        }
        if(employee instanceof Employee){
            System.out.println(employee);
        }

        server.close();
    }
}
